package org.telegram.bot.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import lombok.extern.slf4j.Slf4j;
import org.telegram.bot.domain.BotMenu;
import org.telegram.bot.service.IBotMenuService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * Bot菜单Controller
 *
 * @author wyx
 * @date 2023-05-31
 */
@RestController
@RequestMapping("/bot/menu")
@Slf4j
public class BotMenuController extends BaseController
{
    @Autowired
    private IBotMenuService botMenuService;

    /**
     * 查询Bot菜单列表
     */
    @PreAuthorize("@ss.hasPermi('bot:menu:list')")
    @GetMapping("/list")
    public AjaxResult list(BotMenu botMenu)
    {
        List<BotMenu> list = botMenuService.selectBotMenuList(botMenu);
        return AjaxResult.success(list);
    }

    /**
     * 导出Bot菜单列表
     */
    @PreAuthorize("@ss.hasPermi('bot:menu:export')")
    @Log(title = "Bot菜单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BotMenu botMenu)
    {
        List<BotMenu> list = botMenuService.selectBotMenuList(botMenu);
        ExcelUtil<BotMenu> util = new ExcelUtil<BotMenu>(BotMenu.class);
        util.exportExcel(response, list, "Bot菜单数据");
    }

    /**
     * 获取Bot菜单详细信息
     */
    @PreAuthorize("@ss.hasPermi('bot:menu:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(botMenuService.selectBotMenuById(id));
    }

    /**
     * 新增Bot菜单
     */
    @PreAuthorize("@ss.hasPermi('bot:menu:add')")
    @Log(title = "Bot菜单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BotMenu botMenu)
    {
        return toAjax(botMenuService.insertBotMenu(botMenu));
    }

    /**
     * 修改Bot菜单
     */
    @PreAuthorize("@ss.hasPermi('bot:menu:edit')")
    @Log(title = "Bot菜单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BotMenu botMenu)
    {
        return toAjax(botMenuService.updateBotMenu(botMenu));
    }

    /**
     * 删除Bot菜单
     */
    @PreAuthorize("@ss.hasPermi('bot:menu:remove')")
    @Log(title = "Bot菜单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(botMenuService.deleteBotMenuByIds(ids));
    }
}
